package 左哥算法.compare.comparator;


import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Collection;
import java.util.Random;
import java.util.Set;

public class Container {
    public StringBuilder context=new StringBuilder();
    public static Random r=new Random();

    public Container next(int range){
        return add(r.nextInt(range) + 1);
    }
    public Container nextEnd(int range){
        return addEnd(r.nextInt(range) + 1);
    }
    public Container nextInts(int count,int range){
        while (count-- > 0) {
            add(r.nextInt(range)+1);
        }
        br();
        return this;
    }



    public Container add(Object arg){
        context.append(arg.toString()).append(" ");
        return this;
    }
    public Container addEnd(Object arg){
        context.append(arg.toString());
        return br();
    }
    public Container addAll(Object[] args){
        for (Object arg : args) {
            context.append(arg).append(" ");
        }
        return removeTail();
    }

    public Container addAll(Collection args){
        for (Object arg : args) {
            context.append(arg).append(" ");
        }
        return removeTail();
    }
    public Container addAllEnd(Object[] args){
        return addAll(args).br();
    }
    public Container br(){
        context.append("\n");
        return this;
    }
    public Container removeTail(){
        context.deleteCharAt(context.length()-1);
        return this;
    }
    public InputStream stream(){
        return new ByteArrayInputStream(context.toString().getBytes());
    }

    @Override
    public String toString() {
        return context.toString();
    }

    public void addAllEnd(Set<Integer> set) {

    }
}
